<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>获取当前位置并显示在百度地图中</title>
        <style>
        	*{margin: 0;padding:0;}
        	html,body{
        		width: 100%;
        		height: 100%;
        	}
        	#container{
        		width: 100%;
        		height: 100%;
        	}
        </style>
        <script src="http://api.map.baidu.com/api?v=2.0&ak=7c1a1e865da3cd9af7d5c5316a2525c1" type="text/javascript"></script>
    </head>
    <body>
    	<div id="container"></div>
    	<script>
    		//console.log(window.navigator.geolocation);
    		if(window.navigator.geolocation){
    			var options = {
    				enableHighAccuracy:false,  //是否高精度获取地理位置
    				timeout:30000,
    				maximumAge:60000    //重复获取的时间间隔
    			};

    			window.navigator.geolocation.getCurrentPosition(successCallback,errorCallback,options);
    		}

    		function successCallback(position){
    			var latitude = position.coords.latitude; //纬度
    			var longitude = position.coords.longitude; //经度

    			console.log("纬度为："+latitude);
    			console.log("经度为："+longitude);

    			var map = new BMap.Map("container");          // 创建地图实例  
				var point = new BMap.Point(longitude, latitude);  // 创建点坐标  
				map.centerAndZoom(point, 15);                 // 初始化地图，设置中心点坐标和地图级别  

				var marker = new BMap.Marker(point);   //生成标注
				map.addOverlay(marker);    //将生成的标注放在地图上
    		}

    		function errorCallback(e){
    			console.log(e);
    		}
    		
    	</script>
    </body>
</html>